package huy.mmt.gamelathinh.dialog;

import huy.mmt.gamelathinh.Logo;
import huy.mmt.gamelathinh.Play;
import huy.mmt.gamelathinh.R;
import huy.mmt.gamelathinh.components.Difficulty;
import huy.mmt.gamelathinh.components.Level;
import huy.mmt.gamelathinh.components.Score;
import huy.mmt.gamelathinh.config.Config;
import huy.mmt.gamelathinh.database.MyDataHeaper;
import huy.mmt.gamelathinh.database.ScoreData;
import huy.mmt.gamelathinh.util.Util;
import huy.mmt.gamelathinh.util.UtilDialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

/**
 * Hiá»‡n thá»‹ khi cáº§n lÆ°u Ä‘iá»ƒm ngÆ°á»�i chÆ¡i. Náº¿u ngÆ°á»�i chÆ¡i Ä‘áº¡t Ä‘iá»ƒm top 10 thÃ¬
 * dialog nÃ y má»›i hiá»‡n thá»‹. Khi lÆ°u Ä‘iá»ƒm ngÆ°á»�i chÆ¡i chá»‰ cáº§n nháº­p thÃªm tÃªn.
 * 
 * @author VAN GIOI
 * 
 */
public class DialogSaveScore extends Dialog {
	Activity activity;
	EditText editText_name;
	public static Config config;

	public DialogSaveScore(final Context context) {
		super(context);
		UtilDialog.iniDialog(this);
		activity = (Activity) context;

		setContentView(R.layout.dialog_savescore);

		// resize dialog
		RelativeLayout linearLayout3 = (RelativeLayout) findViewById(R.id.linearlayout_all_savescore);
		Util.resizeDialog(linearLayout3);

		editText_name = (EditText) findViewById(R.id.edit_save);
		config = new Config();

		Button button_yes = (Button) findViewById(R.id.bt_save);
		button_yes.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Logo.ms_click.start();

				// Náº¿u ngÆ°á»�i chÆ¡i khÃ´ng nháº­p tÃªn thÃ¬ láº¥y tÃªn máº·c Ä‘á»‹nh lÃ  Player
				String name = editText_name.getText().toString();
				if (name.length() == 0) {
					name = "Player";
				}

				MyDataHeaper mData = new MyDataHeaper(context);
				mData.openDatabase();
				mData.addScore(new ScoreData(name, Score.score_current,
						Config.THEMES));
				mData.closeDatabase();
				DialogSaveScore.this.dismiss();
				Util.showToast(context, "Save success.");

				Play.mPlay.finish();
				// Reset cac thuoc tinh game : Score, Level
				Level.level_current = 1;
				Score.score_current = 0;
			}
		});

	}
}